package model

import "myserver/app/types"

func CreateUserShopTable() {
	p := &types.UserShop{}
	tables = append(tables, *p)
}

func AddShop(list *[]types.UserShop) error {
	err := db.Create(list).Error
	if err != nil {
		return err
	}
	return err
}

func UpDataShop(list *[]types.UserShop) error {
	var err error
	tx := db.Begin()
	err = tx.Save(list).Error
	if err != nil {
		tx.Rollback()
	} else {
		tx.Commit()
	}
	return err
}

func FindShopByUUids(uuids ...string) ([]types.UserShop, error) {
	var Shops []types.UserShop
	var err error
	tx := db.Begin()
	if len(uuids) > 0 {
		err = tx.Where("uuid IN ? AND is_del=?", uuids, 0).Find(&Shops).Error
	} else {
		err = tx.Where("is_del=?", 0).Find(&Shops).Error
	}
	if err != nil {
		tx.Rollback()
	} else {
		tx.Commit()

	}
	return Shops, err
}
